package cn.org.xuanguang.kepler.hormos.orm.service;

import cn.org.xuanguang.kepler.hormos.orm.dao.HormsBaseSyncRepository;
import cn.org.xuanguang.kepler.hormos.orm.result.PagerResult;
import cn.org.xuanguang.kepler.hormos.rdb.dml.operator.delete.DeleteOperatorResulet;
import cn.org.xuanguang.kepler.hormos.rdb.dml.operator.insert.InsertOperatorResulet;
import cn.org.xuanguang.kepler.hormos.rdb.dml.operator.update.UpdateOperatorResulet;
import cn.org.xuanguang.kepler.hormos.rdb.dsl.param.QueryParam;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
 * 常规化curd操作
 *
 * @param <E>
 * @param <K>
 */
public abstract class GenericCrudIService<E, K> implements IService<E, K> {

    private HormsBaseSyncRepository<E, K> repository;

    public E queryById(K primaryKey) {
        return getRepository().queryById(primaryKey);
    }

    public List<E> queryById(K... primaryKey) {
        return getRepository().queryById(primaryKey);
    }

    public List<E> queryById(Collection<K> primaryKey) {
        return getRepository().queryById(primaryKey);
    }

    public List<E> queryAll() {
        return getRepository().queryAll();
    }

    public PagerResult<E> query(QueryParam queryParam) {
        return getRepository().query(queryParam);
    }

    public int count(QueryParam queryParam) {
        return getRepository().count(queryParam);
    }

    public InsertOperatorResulet insert(E data) {
        return getRepository().insert(data);
    }
    public InsertOperatorResulet insertBatch(E... data){
        return getRepository().insertBatch(List.of(data));
    };
    public InsertOperatorResulet insertBatch(Collection<E> data){
        return getRepository().insertBatch(data);
    };
    public UpdateOperatorResulet updateById(E data) {
        return getRepository().updateById(data);
    }


    public DeleteOperatorResulet delete(E data) {
        return getRepository().delete(data);
    }

    public DeleteOperatorResulet deleteById(K id) {
        return getRepository().deleteById(id);
    }


}
